package com.hdaccp.gymxmjpa.Controller;

import com.hdaccp.gymxmjpa.Dao.CardsinfoDao;
import com.hdaccp.gymxmjpa.Dao.MemberttypeDao;
import com.hdaccp.gymxmjpa.Service.CardsinfoDaoImpl;
import com.hdaccp.gymxmjpa.Service.MembertypeDaoImpl;
import com.hdaccp.gymxmjpa.entity.Cardsinfo;
import com.hdaccp.gymxmjpa.entity.Membertype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Controller
@RequestMapping("/metype")
public class MetypeController {
   @Autowired
    private MembertypeDaoImpl membertypeDaoImpl;
   @Autowired
   private MemberttypeDao memberttypeDao;

 @RequestMapping("/del")
    @ResponseBody
    public  Map<String,Object> del(long typeId,String typeName, int pageSize, int pageNumber){
     memberttypeDao.deleteById(typeId);
     Map<String,Object>  map1=new HashMap<String,Object>();
     map1.put("typeName",typeName);
     map1.put("qi",(pageNumber-1)*pageSize);
     map1.put("shi",pageSize);
     return membertypeDaoImpl.query(map1);
    }
    @RequestMapping("/add")
    @ResponseBody
    public  void save(Membertype membertype){

        memberttypeDao.save(membertype);
    }
    @RequestMapping("/cha")
    @ResponseBody
    public Optional<Membertype> one(long typeId){
        return memberttypeDao.findById(typeId);
    }
    @RequestMapping("/upd")
    @ResponseBody
    public  void upd(Membertype membertype){
        memberttypeDao.save(membertype);
    }


}
